package com.pn.controller;

import com.pn.entity.ProductType;
import com.pn.entity.Result;
import com.pn.service.ProductTypeService;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/productCategory")
public class ProductTypeController {
    @Resource
    private ProductTypeService productTypeService;

    @RequestMapping("/product-category-tree")
    public Result findProductCategory(){
        List<ProductType> productTypeTree = productTypeService.findProductTypeTree();
        return Result.ok(productTypeTree);
    }

    @RequestMapping("/verify-type-code")
    public Result verifyTypeCode(String typeCode){
        Result result = productTypeService.findProductTypeCode(typeCode);
        return result;
    }

    //添加产品分类
    @RequestMapping("/type-add")
    public Result addProductType(@RequestBody ProductType productType){
        Result result = productTypeService.addProductType(productType);
        return result;
    }
    //删除产品分类
    @RequestMapping("/type-delete/{typeId}")
    public Result removeProductType(@PathVariable Integer typeId){
        Result result = productTypeService.removeProductType(typeId);
        return result;
    }

    //更新产品分类
    @RequestMapping("/type-update")
    public Result modifyProductType(@RequestBody ProductType productType){
        Result result = productTypeService.modifyProductType(productType);
        return result;
    }
}
